#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/12/17 15:38
# @Author : 鲍盈廷
# @File : app.py
from zentao.zentao import ZenTao
from zentao.casedata import CaseData
from flask import request, Flask
import json

app = Flask(__name__)


@app.route('/XMind/input', methods=['POST'])
def xmind_input_zentao_post():
    """
    @api {post} /XMind/input
    @apiName interfacecaseDel
    @apiGroup Interface
    @apiDescription 导入用例到禅道
  """
    data = request.json
    import_type = data.get('import_type')
    path = data.get('path')
    print('--------获取数据------------')
    case_data = ZenTao(import_type, path).check_case_type()
    input_case = case_data.zt_case
    print('----------导入禅道-------------')
    res_input_cases = CaseData.sync_zt_case(case_data)
    msg = '导入成功'
    if len(input_case) != len(res_input_cases):
        msg = '导入失败'

    res = {"msg": msg, 'msg_code': 0, "data": {"count": len(input_case), "input_cases": len(res_input_cases)}}
    return json.dumps(res, ensure_ascii=False)


@app.route('/XMind/input', methods=['GET'])
def xmind_input_zentao_get():
    """
    @api {post} /XMind/input
    @apiName interfacecaseDel
    @apiGroup Interface
    @apiDescription 导入用例到禅道
  """
    import_type = request.args.get('import_type')
    path = request.args.get('path')
    print('--------获取数据------------')
    case_data = ZenTao(import_type, path).check_case_type()
    input_case = case_data.zt_case
    print('----------导入禅道-------------')
    res_input_cases = CaseData.sync_zt_case(case_data)
    msg = '导入成功'
    if len(input_case) != len(res_input_cases):
        msg = '导入失败'

    res = {"msg": msg, 'msg_code': 0, "data": {"count": len(input_case), "input_cases": len(res_input_cases)}}
    return json.dumps(res, ensure_ascii=False)
if __name__ == '__main__':

    app.run(port=8999, debug=True, host='0.0.0.0')
